package cn.kduck.module.message;

import cn.kduck.module.message.service.MailMessageService;
import cn.kduck.module.message.service.SmsMessageSender;
import cn.kduck.module.message.service.impl.MailMessageServiceImpl;
import cn.kduck.module.message.service.sender.AliyunSmsMessageSender;
import cn.kduck.module.message.service.sender.TencentSmsMessageSender;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
@EnableConfigurationProperties({ SmsServiceProperties.class,MailProperties.class})
public class SmsMessageConfiguration {

    @Bean
    @ConditionalOnClass(name="com.tencentcloudapi.sms.v20190711.SmsClient")
    public SmsMessageSender tencentSmsMessageSender(SmsServiceProperties properties){
        return new TencentSmsMessageSender(properties);
    }

    @Bean
    @ConditionalOnClass(name="com.aliyun.dysmsapi20170525.Client")
    public SmsMessageSender aliyunSmsMessageSender(SmsServiceProperties properties){
        return new AliyunSmsMessageSender(properties);
    }

    @Bean
//    @ConditionalOnBean(MailSender.class)
    public MailMessageService mailMessageService(MailProperties mailProperties){
        return new MailMessageServiceImpl(mailProperties);
    }
}
